package io.zw.modules.xinpai.controller;

import java.util.Arrays;
import java.util.Map;

import io.zw.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.zw.modules.xinpai.entity.CarProjectEntity;
import io.zw.modules.xinpai.service.CarProjectService;
import io.zw.common.utils.PageUtils;
import io.zw.common.utils.R;



/**
 * 
 *
 * @author zhuwei
 * @email 121203654@qq.com
 * @date 2018-10-13 15:41:02
 */
@RestController
@RequestMapping("xinpai/carproject")
public class CarProjectController {
    @Autowired
    private CarProjectService carProjectService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("xinpai:carproject:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = carProjectService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{carProjectId}")
    @RequiresPermissions("xinpai:carproject:info")
    public R info(@PathVariable("carProjectId") Integer carProjectId){
        CarProjectEntity carProject = carProjectService.selectById(carProjectId);

        return R.ok().put("carProject", carProject);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("xinpai:carproject:save")
    public R save(@RequestBody CarProjectEntity carProject){
        carProjectService.insert(carProject);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("xinpai:carproject:update")
    public R update(@RequestBody CarProjectEntity carProject){
        ValidatorUtils.validateEntity(carProject);
        carProjectService.updateAllColumnById(carProject);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("xinpai:carproject:delete")
    public R delete(@RequestBody Integer[] carProjectIds){
        carProjectService.deleteBatchIds(Arrays.asList(carProjectIds));

        return R.ok();
    }

}
